package com.heima.comment.controller;


import com.heima.comment.model.dto.CommentLikeDto;
import com.heima.comment.model.dto.CommentListDto;
import com.heima.comment.model.dto.CommentSaveDto;
import com.heima.comment.service.CommentService;
import com.heima.common.constants.CommentConstants;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/v1/comment")
public class CommentController {

    @Resource
    private CommentService commentService;

    /**
     * 发布评论
     *
     * @param dto
     * @return
     */
    @PostMapping("/save")
    public ResponseResult saveComment(@RequestBody CommentSaveDto dto) {
        return commentService.save(dto.getArticleId(), dto.getContent(), CommentConstants.COMMENT_TARGET_ARTICLE);
    }

    /**
     * 点赞评论
     *
     * @param dto
     * @return
     */
    @PostMapping("/like")
    public ResponseResult like(@RequestBody CommentLikeDto dto) {
        return commentService.like(dto.getCommentId(), dto.getOperation());
    }

    /**
     * 加载评论列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/load")
    public ResponseResult load(@RequestBody CommentListDto dto) {
        return commentService.load(dto.getArticleId(), dto.getSize(), dto.getMinDate());
    }

}